<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="common/head :: htmlhead">
<body>
<script th:src="@{/static/plugins/ueditor/ueditor.config.js}"></script>
<script th:src="@{/static/plugins/ueditor/ueditor.all.min.js}"> </script>
<script th:src="@{/static/plugins/ueditor/lang/zh-cn/zh-cn.js}"></script>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">联盟简介修改</div>
                <div class="layui-card-body">
                    <form class="layui-form" id="form1" action="" lay-filter="component-form-element">
                        <div class="layui-row layui-col-space10 layui-form-item">
                            <div class="layui-col-lg12">
                                <div>
                                    <script id="editor" type="text/plain" style="width:100%;height:500px;"></script>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-upload" th:if="${type} eq 'lmzc'">
                                <button type="button" class="layui-btn layui-btn-normal" id="uploadFile">上传章程文件</button>
                            </div>
                        </div>


                        <div class="layui-form-item">
                            <input id="type" th:value="${type}" type="hidden">
                            <button type="button" class="layui-btn" onclick="update()">提交</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript"  th:inline="javascript">
    layui.use(['layer','upload'], function(){
        var layer = layui.layer
            ,upload = layui.upload;

        upload.render({
            elem: '#uploadFile'
            ,accept: 'file'
            ,url: '/upload_lmzc'
            ,done: function(res){
                if(res.data==="fileTypeError"){
                    layer.msg('文件类型错误！', {icon: 2});

                }else if(res.data==="fileTypeError"){
                    layer.msg('文件已存在！', {icon: 2});

                }else if(res.data==="Error"){
                    layer.msg('上传文件失败！', {icon: 2});

                }else{
                    layer.msg('上传文件成功！', {icon: 1});
                }
            }
        });

    });

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    $(function () {
        var ue = UE.getEditor('editor');
        ue.addListener("ready", function () {
            //赋值
            ue.setContent([[${context}]])
        });
    });

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');


    function update(){
        var context = UE.getEditor('editor').getContent();
        var type = $("#type").val();
        var datas = {};
        datas["context"] = context;
        datas["type"] = type;
        $.ajax({
            url:"/updatecommonintro",
            async: false,
            type:"POST",
            dataType: "json",
            contentType:"application/json",
            data:JSON.stringify(datas),
            success: function(data){
                if(data.res==="success"){
                    layer.open({
                        title: '提交成功',
                        content: '操作成功！'
                        ,btn: ['确定']
                        ,yes: function(index, layero){
                            location.reload();
                        }
                    });
                }
            }
        });
    }

</script>
</body>
</html>